package com.action;

import com.util.GzhServiceUtil;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;
import java.util.ArrayList;

//@Component
public class SpringStart implements ApplicationRunner {

    @Value("${host}")
    private String host;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        WxMenu wxMenu = new WxMenu();


        WxMenuButton button1 = new WxMenuButton();
        button1.setType("view");
        button1.setName("携联商城");
        System.out.println(GzhServiceUtil.get("test").getWxMpConfigStorage().getAppId()+"**************");
        String btn1Url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="
                + GzhServiceUtil.get("test").getWxMpConfigStorage().getAppId()
                + "&redirect_uri="
                + URLEncoder.encode(host + "gzh.do?p=xlsc", "utf-8")
                + "&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
        button1.setUrl(btn1Url);
        WxMenuButton button2 = new WxMenuButton();
        button2.setType("view");
        button2.setName("求实教育");
//        String btn23Url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="
//                + GzhServiceUtil.get("test").getWxMpConfigStorage().getAppId()
//                + "&redirect_uri="
//                + URLEncoder.encode(host + "gzh.do?p=kysc", "utf-8")
//                + "&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
        String btn23Url = host+":8082/index.html";
        button2.setUrl(btn23Url);
        wxMenu.setButtons(new ArrayList<WxMenuButton>() {{
            add(button1);
            add(button2);
        }});
        // 设置菜单
        GzhServiceUtil.get("test").getMenuService().menuCreate(wxMenu);
    }
}
